home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / plain / contrib / autotoc.tex < prev    next >
Encoding:
Text File  |  1992-08-26  |  2.3 KB  |  54 lines

  1. %
  2. % Automatically generate a Table Of Contents (TOC) while the
  3. % document is being processed by PLAIN TeX
  4. %
  5. % Use \tocref{ texta }{ textb } to insert TOC entries. `texta'
  6. %         will be typeset in the TOC and at the current location,
  7. %         for example `\centerline{\tocref{Chapter 1}{}}' inserts
  8. %         `Chapter 1' at the current location in your document
  9. %         centered, and enters it in the TOC (not centered).
  10. %         `textb' is a prefix text/TeX commands to precede `texta'
  11. %         in the TOC only (it will not appear in the current loc-
  12. %         ation of your document -- {{`textb'`texta'}.....\folio}).
  13. % Use \tocline to add info only intended for the TOC (no page number or
  14. %         dotfill is used for tocline entries).
  15. % Use \tocgen to force the last TOC page to be printed (last command
  16. %         before \end?)
  17. % To specialize, look at the below comments in the right
  18. %
  19. % Uses variable names
  20. %         tocnew, tocopage, tocbox, tocsize, tocstrut, tocref,
  21. %         tocbanner, tocsuffix, tocline, tocstart, tocont, tocgen
  22. %
  23. \newcount\tocnew\tocnew=1\newcount\tocopage
  24. \newbox\tocbox\newdimen\tocsize
  25. \def\tocstrut{{\vrule height8.5pt depth3.5pt width0pt}} % TOC baselineskip -1pt
  26. \def\tocref#1#2{\tocbanner#1               % Where `texta' is duplicated
  27.     \global\setbox\tocbox=\vbox{
  28.     \box\tocbox\vbox{
  29.     \line{\tocstrut{#2#1}~\dotfill~\folio} % Where the TOC line is made
  30.     }}\tocsuffix}
  31. \def\tocline#1{\tocbanner
  32.     \global\setbox\tocbox=\vbox{
  33.     \box\tocbox\vbox{
  34.     \line{\tocstrut{#1}}
  35.     }}\tocsuffix}
  36. \def\tocbanner{\ifnum\tocnew=1\tocstart\fi
  37.     \ifnum\tocnew=3\tocont\fi}
  38. \def\tocsuffix{\ifdim\tocsize<\ht\tocbox\tocgen
  39.     \global\tocnew=3\fi}
  40. % Do not change tocsize = 1.0 (TeX may go into an infinite loop)
  41. \def\tocstart{\global\tocsize=.95\vsize   % TOC page >95% full, print it
  42.     \global\setbox\tocbox=\vbox{
  43.     \centerline{\tocstrut\bf Table Of Contents} % TOC page 1 banner line 1
  44.     \line{\tocstrut\hfil}                 % TOC page 1 banner line 2 blank line
  45.     }\global\tocnew=2}
  46. \def\tocont{\global\setbox\tocbox=\vbox{
  47.     \centerline{\tocstrut Table Of Contents (Continued)} % TOC page <> 1 banner
  48.     }\global\tocnew=2}
  49. \def\tocgen{\ifnum\tocnew=1
  50.     \message{No TOC entries found.}\else
  51.     \tocopage=\pageno\pageno=0\message{(TOC}
  52.     \shipout\box\tocbox\message{)}
  53.     \pageno=\tocopage\global\tocnew=1\fi}
  54.